<template>
	<view>
		<view class="login-title">一键登录</view>
		
		<view class="login-content">
			<view class="phone-title">{{phone}}</view>
			<view class="title-txt grey">认证服务由手机服务商提供</view>
			<MyBtn title="立即登录" @click="formSubmit"></MyBtn>
		</view>
		
		<Footer></Footer>
	</view>
</template>		
 	
<script>
import Footer from './common/footer.vue'  //底部通用
import { passwordLogin } from '@/api/login.js'

export default {
	components:{
		Footer
	},
	data() {
		return {
			phone: "1********",
			form: {
				username:''
			}
		}
	},
	onLoad() {
		this.getPhone();
	},
	methods: {
		// 跳转页面
		openPage(url){
			this.$utils.navigateTo(url);
		},
		// 登录跳转
		getPhone(){
			uni.login({
				provider: 'univerify',
				//univerifyStyle:  v_univerifyStyle,
				// #ifdef MP-ALIPAY
				scopes: 'auth_user', // 支付宝小程序需设置授权类型
				// #endif
				success: async (res) => {
					uniCloud.callFunction({
						name: 'getPhoneNumber', // 你的云函数名称
						data: {
							'access_token': res.authResult.access_token, // 客户端一键登录接口返回的access_token
							'openid': res.authResult.openid // 客户端一键登录接口返回的openid
						}
					}).then(res => {
						uniCloud.callFunction({
							name: 'getPhoneNumber', // 你的云函数名称
							data: {
								'access_token': res.authResult.access_token, // 客户端一键登录接口返回的access_token
								'openid': res.authResult.openid // 客户端一键登录接口返回的openid
							}
						}).then(res => {
							console.log(res.result);
							if(res.result.data.code == 0){
								this.Toast({
									title: res.result.data.message
								})
							}else{
								
								/*uni.setStorageSync('token', res.result.data.token);
								this.$utils.redirectTo('ucenter/ucenter');
								uni.closeAuthView(); 
								this.Toast({
									title: '登录成功'
								})*/
							}
						}).catch(err=>{});
					});
				}
			});
		},
		// 登录跳转
		formSubmit(){
			this.$refs.uForm.validate(valid => {
				if (valid) {
					passwordLogin(this.form).then(res=>{
						//uni.setStorageSync('token', res.token);
						this.$store.commit('PUBLICLOGIN', res);
						this.$utils.switchTab('/index/index');
					}).catch(err=>{
						uni.showToast({
							title: res.msg,
							icon:'none'
						})
					});
				}
			});
		}
	}
}
</script>

<style lang="scss" scoped>
.login-title{
	margin-top:200rpx;
}
.login-content{
	padding:70rpx;
	.phone-title{
		margin-top: 150rpx;
		font-size: 95rpx;
		font-weight: bold;
		text-align: center;
	}
	.title-txt{
		text-align: center;
		margin: 25rpx 0 130rpx;
	}
}
</style>